<?php

namespace app\api\controller;

use app\common\exception\BusinessException;
use think\response\Json;

class Sso extends Base
{
    /**
     * createLoginQr
     * @return Json
     * @throws BusinessException
     */
    public function createLoginQr(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 提交生成
        $response = (new \app\api\logic\Sso())->createLoginQr($param);

        // 返回
        return $this->response($response);
    }

    /**
     * checkLoginQr
     * @return Json
     * @throws BusinessException
     */
    public function checkLoginQr(): Json
    {
        // 外部参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'reqId' => 'require',
        ];

        // 错误信息
        $errMsg = [];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 提交查询
        $response = (new \app\api\logic\Sso())->checkLoginQr($param);

        // 返回
        return $this->response($response);
    }


    /**
     * confirmLoginQr
     * @return Json
     * @throws BusinessException
     */
    public function confirmLoginQr(): Json
    {
        // 外部参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'reqId' => 'require',
        ];

        // 错误信息
        $errMsg = [];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 提交确认
        (new \app\api\logic\Sso())->confirmLoginQr($param);

        // 返回
        return $this->response();
    }

}